package ccnt.pvc.scudwaremobile.activity;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.view.Window;
import android.view.WindowManager;
import ccnt.pvc.scudwaremobile.R;
import ccnt.pvc.scudwaremobile.utils.Constants.PreferenceNames;

public class SplashActivity extends Activity {

	private final static long DELAY_TIME = 2000;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
				WindowManager.LayoutParams.FLAG_FULLSCREEN);
		setContentView(R.layout.activity_splash);

		SharedPreferences preference = getSharedPreferences(
				PreferenceNames.LOGIN_PREFERENCE, MODE_PRIVATE);
		final boolean isLogin = preference.getBoolean("isLogin", false);

		new Handler().postDelayed(new Runnable() {

			@Override
			public void run() {
				Intent intent = null;
				if(isLogin) {
					intent = new Intent(SplashActivity.this, MainActivity.class);
				}
				else {
					intent = new Intent(SplashActivity.this, LoginActivity.class);
				}
				startActivity(intent);
				finish();
			}
		}, DELAY_TIME);
	}
}
